from openpyxl import load_workbook
from openpyxl.worksheet.worksheet import Worksheet


class ExcelHandler:
    def __init__(self, file):
        self.file = file

    def open_sheet(self, sheet_name) -> Worksheet:
        wb = load_workbook(self.file)
        sheet = wb[sheet_name]
        return sheet

    def read_header(self, sheet_name):
        sheet = self.open_sheet(sheet_name)
        headers = []
        for cell in sheet[1]:   # 第一行
            headers.append(cell.value)
        return headers


if __name__ == "__main__":
    headers = sheet = ExcelHandler("测试.xlsx").open_sheet("工作业务")
    print(headers)
    # for row in sheet.rows:
    #     for cell in row:
    #         print(cell.value, " ", end=" ")
    #     print()
